package com.dormitory.dormitorymanagement.controller;


import com.dormitory.dormitorymanagement.pojo.DormRepair;
import com.dormitory.dormitorymanagement.pojo.StudentEvaluations;
import com.dormitory.dormitorymanagement.pojo.dto.DormRepairDto;
import com.dormitory.dormitorymanagement.pojo.PageBean;
import com.dormitory.dormitorymanagement.pojo.Result;
import com.dormitory.dormitorymanagement.pojo.dto.NoticeDto;
import com.dormitory.dormitorymanagement.service.AdminService;
import com.mysql.cj.protocol.x.Notice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/admin")
@CrossOrigin(origins = "http://localhost:8081", allowedHeaders = "*")
public class AdminController {



    @Autowired
    AdminService adminService;
    @GetMapping("/repair")
     public Result<PageBean<DormRepair>> repair(DormRepairDto dormRepairDto)
    {


        PageBean<DormRepair> dormRepairPageResult = adminService.repairList(dormRepairDto);
        return Result.success(dormRepairPageResult);

    }


    @PostMapping("handle/{repairId}/status")
     public Result updateStatus(
            @PathVariable("repairId") Integer repairId,
            @RequestBody DormRepairDto  dormRepairDto
    ) {

        adminService.updateStatus(repairId,dormRepairDto.getStatus());


        return Result.success();
    }


    @PostMapping("/notice")
    public Result notice(@RequestBody NoticeDto noticeDto) {
        adminService.notice(noticeDto);
        return Result.success();
    }


    @GetMapping("/classmateevaluation")
    public Result<PageBean<StudentEvaluations>>  getStudentClassmateEvaluations(@RequestParam String studentId, @RequestParam Integer page, @RequestParam Integer pageSize){

        return Result.success(adminService.getStudentClassmateEvaluations(studentId,page,pageSize));
    }


}


